using Identity.Application.PermissionKeyResourceIds.Interfaces;
using Identity.Infrastructure.Persistence.Entities;


namespace Identity.Infrastructure.Persistence.Repositories;
public class PermissionKeyResourceIdRepository : IApiPermissionBindingRepository
    {
        private readonly ApplicationDbContext _dbContext;

        public PermissionKeyResourceIdRepository(ApplicationDbContext dbContext)
        {
            _dbContext = dbContext;
        }
        public void Add(ApiPermissionBinding apiPermission)
        {

            _dbContext.ApiPermissionBindings.Add(apiPermission);

        }

        public ApiPermissionBinding? GetByResourceId(string resourceId)
        {
            var pkrid = _dbContext.ApiPermissionBindings.FirstOrDefault(p => p.ResourceId == resourceId);
            if (pkrid == null) return null;
            return pkrid;
        }

        public void Remove(ApiPermissionBinding apiPermission)
        {

            _dbContext.ApiPermissionBindings.Remove(apiPermission);

        }



        public void Update(ApiPermissionBinding permissionKeyResource)
        {

            _dbContext.ApiPermissionBindings.Update(permissionKeyResource);

        }

       
    }